package com.example.fw;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public class HelperWithWebDriverBase {

	protected final AppManager manager;
	private WebDriver driver;

	public HelperWithWebDriverBase(AppManager manager) {
		this.manager = manager;
		driver = manager.getWebDriverHelper().getDriver();
	}

	protected void type(By locator, String paramvalue) {
		if (paramvalue != null) {
			driver.findElement(locator).clear();
			driver.findElement(locator).sendKeys(paramvalue);
		}
	}

	protected void typeselect(By locator, String optionvalue) {
		new Select(driver.findElement(locator))
				.selectByVisibleText(optionvalue);
	}

	protected void submitFilledFormCreation() {
		click(By.name("submit"));
	}

	protected WebElement findElement(By locator) {
		return driver.findElement(locator);
	}

	protected List<WebElement> findElements(By locator) {
		return driver.findElements(locator);
	}

	protected void openUrl(String mainPage) {
		driver.get(mainPage);
	}

	protected void click(By locator) {
		findElement(locator).click();
	}

}
